import { axios } from '@/utils/request'
import { METHOD } from '@/store/mutation-types'
import { REFRESH_TOKEN, LOGOUT, LOGIN } from '@/services/api'
/**
 * 登录服务
 * @param name 账户名
 * @param password 账户密码
 * @returns {Promise<AxiosResponse<T>>}
 */
export function login(name, password) {
  return axios({
    url: LOGIN,
    method: METHOD.POST,
    data: {
      username: name,
      password: password
    }
  })
}

/**
 * 退出
 * @param  username 账户名
 * @returns {Promise<AxiosResponse<T>>}
 */
export function logout(name) {
  return axios({
    url: LOGOUT,
    method: METHOD.POST,
    data: { username: name }
  })
}

export function getRoutesConfig() {
  return axios({
    url: '/permiss/url/list',
    method: METHOD.GET
  })
}

export function loadRefreshToken(refreshToken) {
  return axios({
    url: REFRESH_TOKEN,
    method: METHOD.POST,
    data: { refreshToken: refreshToken }
  })
}

export default {
  login,
  logout,
  getRoutesConfig
}
